<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>修改员工界面</h1>
<form action="">
    <input type="text" name="id" v-model="emp.id" placeholder="id">
    <input type="text" name="name" v-model="emp.name" placeholder="名字">
    <input type="text" name="job" v-model="emp.job" placeholder="工作">
    <input type="text" name="sal" v-model="emp.sal" placeholder="工资">
    <input type="button" value="修改" @click="update()">
</form>

<!--引入vue和axios-->
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<script>
    let v = new Vue({
        el:"form",
        data:{
            emp:{}
        },
        created:function () {
            //得到地址栏中的id
            let id = location.search.split("=")[1];
            console.log("id="+id);
            //发出异步请求
            axios.get("/SelectById?id="+id).then(function (response) {
                v.emp=response.data;
            })
        },
        methods:{
            update:function () {
                let data = new FormData(document.querySelector("form"));
                axios.post("/update",data).then(function (response) {
                    alert("修改完成");
                    location.href="/select.html";//回到列表页面
                })
            }
        }
    })
</script>
</body>
</html>